#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
int n;
char s[200020];
int f[200020][3];   // 'S', 'R', 'P'

int main() {
    scanf("%d", &n);
    scanf("%s", s + 1);
    memset(f, 0xf3, sizeof(f));
    f[0][0] = f[0][1] = f[0][2] = 0;
    for (int i = 1; i <= n; ++ i){
        if(s[i] == 'P'){
            f[i][0] = max(f[i - 1][1], f[i - 1][2]) + 1;
            f[i][2] = max(f[i - 1][1], f[i - 1][0]);
        } else if(s[i] == 'R') {
            f[i][1] = max(f[i - 1][0], f[i - 1][2]);
            f[i][2] = max(f[i - 1][0], f[i - 1][1]) + 1;
        } else {
            f[i][1] = max(f[i - 1][0], f[i - 1][2]) + 1;
            f[i][0] = max(f[i - 1][1], f[i - 1][2]); 
        }
    }
    printf("%d\n", max(f[n][0], max(f[n][1], f[n][2])));
    return 0;
}